<?php
header('Content-Type: text/xml');
header("Cache-Control: no-cache, must-revalidate");
echo "<?xml version='1.0' encoding='UTF-8'?>";


$con = mysql_connect("localhost","cubeMass_f","cubeSelectNow");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("cubeMass", $con);
session_start();


	if($_SESSION[user_id]){
		if(!session_is_registered('comment_'.$_POST['comment_id'])){
		
		
			if($_POST['sup']==1){
				$sql = "SELECT * FROM discuss  WHERE ID = '$_POST[comment_id]'";
				$result = mysql_query($sql,$con);
				$row = mysql_fetch_array($result);
				
				if($row['supportTimes']>=$row['opposeTimes']){
					$rank = $row['rankResult']+0.5;
					}else{
						$rank = $row['rankResult']+1;
						}
				$sup = $row['supportTimes']+1;
				$sql="UPDATE discuss SET supportTimes = '$sup',rankResult = '$rank' WHERE ID = '$_POST[comment_id]'";
				echo $sup;	
				mysql_query($sql,$con);
				echo $rank;
				}elseif($_POST['sup']==-1){
					$sql = "SELECT * FROM discuss WHERE ID = '$_POST[comment_id]'";
					$result = mysql_query($sql,$con);
					$row = mysql_fetch_array($result);
					
					if($row['opposeTimes']<$row['supportTimes']){
						$rank = $row['rankResult']+1;
						}else{
							$rank = $row['rankResult'];
							}
					$sup = $row['opposeTimes']+1;
					$sql="UPDATE discuss SET opposeTimes = '$sup',rankResult = '$rank' WHERE ID = '$_POST[comment_id]'";
					mysql_query($sql,$con);
					}
				
		
			$_SESSION['comment_'.$_POST['comment_id']] = true;
		}else{
			echo "请不要重复点击";
			
			}
		
		
		
		
	}else{
		echo "请登录！";
		}
	
	
	
	mysql_close($con);
?>

